package com.game.module.backpack.view
{
	import com.dusk.util.McUtil;
	import com.dusk.util.ResUtil;
	import com.game.view.component.ComponentBase;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class EquipFuncPanel extends ComponentBase
	{
		public static const EVENT_EQUIP:String = "equip";
		
		public static const EVENT_SELL:String = "sell";
		
		public static const EVENT_USE:String = "use";
		
		public static const EVENT_ABANDON:String = "abandon";
		
		public static const BUTTON_EQUIP:String = "btn_equip";
		
		public static const BUTTON_SELL:String = "btn_sell";
		
		public static const BUTTON_USE:String = "btn_use";
		
		public static const BUTTON_ABANDON:String = "btn_abandon";
		
		public var btn_equip:MovieClip;
		
		public var btn_sell:MovieClip;
		
		public var btn_use:MovieClip;
		
		public var btn_abandon:MovieClip;
		
		override protected function beforeAdded():void
		{
			var mc:MovieClip = ResUtil.getComponentView("EquipFuncPanel") as MovieClip;
			McUtil.stopAllChildren(mc);
			btn_equip = mc.getChildByName(BUTTON_EQUIP) as MovieClip;
			btn_sell = mc.getChildByName(BUTTON_SELL) as MovieClip;
			btn_use = mc.getChildByName(BUTTON_USE) as MovieClip;
			btn_abandon = mc.getChildByName(BUTTON_ABANDON) as MovieClip;
			addChild(mc);
		}
		
		override protected function onAdded():void
		{
			btn_equip.addEventListener(MouseEvent.CLICK, declareEvent);
			btn_sell.addEventListener(MouseEvent.CLICK, declareEvent);
			btn_use.addEventListener(MouseEvent.CLICK, declareEvent);
			btn_abandon.addEventListener(MouseEvent.CLICK, declareEvent);
		}
		
		override protected function onRemoved():void
		{
			btn_equip.removeEventListener(MouseEvent.CLICK, declareEvent);
			btn_sell.removeEventListener(MouseEvent.CLICK, declareEvent);
			btn_use.removeEventListener(MouseEvent.CLICK, declareEvent);
			btn_abandon.removeEventListener(MouseEvent.CLICK, declareEvent);
		}
		
		/**
		 * 设置面板格式，有两个值可选：0、1，0表示显示装备、出售按钮，1表示显示使用、丢弃按钮
		 * @param value 0、1
		 */
		public function setMode(value:int):void
		{
			switch (value)
			{
				case 0:
					btn_equip.visible = true;
					btn_sell.visible = true;
					btn_use.visible = false;
					btn_abandon.visible = false;
					break;
				case 1:
					btn_equip.visible = false;
					btn_sell.visible = false;
					btn_use.visible = true;
					btn_abandon.visible = true;
			}
		}
		
		private function declareEvent(evt:MouseEvent):void
		{
			dispatchEvent(new Event(evt.currentTarget.name.split("_")[1]));
		}
	}
	
}
